package com.company.biz.user.action;


import com.company.biz.user.service.LoginService;
import com.company.biz.user.service.UserLogService;
import com.company.user.req.AddUserLogReq;
import com.company.user.req.LoginReq;
import com.company.user.req.LogoutReq;
import com.company.user.resp.LoginResp;
import com.company.user.vo.GeneralResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;

@Api(description = "登录")
@RestController
@RequestMapping("/login")
public class LoginController extends BaseController {
    @Resource
    private LoginService loginService;
    
    @ApiOperation(value = "登录接口")
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public GeneralResult<LoginResp> login(@RequestBody @Validated LoginReq req) {
        //登入ip地址
        req.setIp(getRemoteIP());
        LoginResp loginResp = loginService.login(req);
        return GeneralResult.genSuccessResult(loginResp);
    }

    @ApiOperation(value = "退出")
    @RequestMapping(value = "/logout", method = RequestMethod.POST)
    public GeneralResult<LoginResp> logout(@RequestBody @Validated LogoutReq req) {
        return  GeneralResult.genSuccessResult(loginService.logout(req));
    }
//
//    @ApiOperation(value = "扫描登入获取公共id")
//    @RequestMapping(value = "/getScanLoginId", method = RequestMethod.POST)
//    public GeneralResult<String> getScanLoginId() {
//        String scanLoginId = loginService.getScanLoginId();
//        return  GeneralResult.genSuccessResult(scanLoginId);
//    }
//    @ApiOperation(value = "App扫描确认登入")
//    @RequestMapping(value = "/scanConfirmLogin", method = RequestMethod.POST)
//    public GeneralResult scanConfirmLogin(@RequestBody @Validated ScanLoginReq req) {
//        if(StringUtils.isEmpty(req.getUserId())){
//            throw new BizException("","请先完成注册后，再进行登录操作!");
//        }
//        loginService.scanConfirmLogin(req);
//        return  GeneralResult.genSuccessResult();
//    }
//
//    @ApiOperation(value = "web确定是否登入")
//    @RequestMapping(value = "/scanLogin", method = RequestMethod.POST)
//    public GeneralResult<LoginResp> scanLogin(@RequestBody @Validated ScanLoginReq req) {
//        LoginResp respData = loginService.scanLogin(req);
//        if(StringUtils.isEmpty(respData.getToken())){
//            respData.setToken("false");
//            return  GeneralResult.genSuccessResult(respData);
//        }else{
//            return  GeneralResult.genSuccessResult(respData);
//        }
//    }
//
//    @ApiOperation(value = "忘记密码")
//    @RequestMapping(value = "/forgotPassword", method = RequestMethod.POST)
//    public GeneralResult forgotPassword(@RequestBody ForgotPsReq req) {
//        loginService.forgotPassword(req);
//        return GeneralResult.genSuccessResult();
//    }
//
//    @ApiOperation(value = "学生登录选择学段 传递学段id")
//    @RequestMapping(value = "/setStudentSectionId", method = RequestMethod.POST)
//    public GeneralResult setStudentSectionId(@RequestBody SingleReq<String> sectionId){
//        String token = getToken();
//        //更新token学段内容
//        UserEntity userEntity = getCurrentUser();
//        userEntity.setSection(sectionId.getSingle());
//        String json = JSONObject.toJSONString(userEntity);
//        RedisUtil.set(token, json);
//        RedisUtil.expire(token,3 , TimeUnit.HOURS);
//        return GeneralResult.genSuccessResult();
//    }


}
